part of '../../repository.dart';

class _YookassaBankCardInfoDto extends Equatable implements _WebBankCardInfoDto {
  const _YookassaBankCardInfoDto._internal({
    required this.last4,
    required this.expirationMonth,
    required this.expirationYear,
    required this.cardTypeDto,
  });

  @override
  final String last4;

  @override
  final String expirationMonth;

  @override
  final String expirationYear;

  @override
  final _WebBankCardTypeDto cardTypeDto;

  @override
  List<Object?> get props {
    return [
      last4,
      expirationMonth,
      expirationYear,
      cardTypeDto,
    ];
  }

  factory _YookassaBankCardInfoDto.fromJson(Map<String, dynamic> json) {
    final cardTypeString = json[_kWebBankCardInfoCardTypeKey] as String;
    final cardTypeDto = _WebBankCardTypeDto.fromString(cardTypeString);

    return _YookassaBankCardInfoDto._internal(
      last4: json[_kWebBankCardInfoLast4Key],
      expirationMonth: json[_kWebBankCardInfoExpirationMonthKey],
      expirationYear: json[_kWebBankCardInfoExpirationYearKey],
      cardTypeDto: cardTypeDto,
    );
  }

  @override
  YookassaBankCardInfo toEntity() {
    return YookassaBankCardInfo(
      last4: last4,
      expirationMonth: expirationMonth,
      expirationYear: expirationYear,
      cardType: cardTypeDto.toEntity(),
    );
  }
}
